<template>
    <div style="background-color: #fff">
        <div v-if="worksInfo.length != 0">
            <el-row class="swiper-painter-item">
                <el-card class="swiper-painter-cards" v-for="(workInfo,index) in worksInfo" :key="index">
                    <button class="work-button" style="border: #ffffff" @click="workDetail(workInfo)">
                        <div v-if="workInfo.workFileType === 1" @click="workDetail(workInfo)">
                            <img class="image" :src="imgUrl+workInfo.workFilename"/>
                        </div>
                        <div @click="workDetail(work)" v-else>
                            <video :poster="workInfo.poster" :controls="true" class="video_fo"
                                   :src="imgUrl+workInfo.workFilename"></video>
                        </div>
                    </button>
                    <div class="work-div">
                            <span class="painter-item-name">
                                {{workInfo.workName}}
                            </span>
                    </div>
                    <div class="introduction-motto">
                        <span class="author-span">
                            <img class="work-user-img" :src="imgUrl+workInfo.userImg">
                            <span class="author-span">
                                {{workInfo.username}}
                            </span>
                        </span>
                        <span class="star-span">
                            <i class="icon-favorites"></i>
                            {{workInfo.workLikesNums}}
                        </span>
                    </div>
                </el-card>
            </el-row>
            <!--页码-->
            <section class="stage-flex-container"
                     style="justify-content: center; align-items: stretch; align-self: auto;">
                <div class="is-darken el-pagination is-background">
                    <el-pagination
                            background
                            layout="prev, pager, next"
                            :total="worksInfo.length">
                    </el-pagination>
                </div>
            </section>
        </div>
    </div>
</template>

<script setup>
  import {selectUserWorks} from "@/assets/api/workInfoApi";
  import {useRoute, useRouter} from "vue-router";
  import {getCurrentInstance, onBeforeMount, ref} from "vue";

  const worksInfo = ref([{}]);
  const centerDialogVisible = ref(false);
  const workImg = ref('');
  const workInfo = ref({});
  const comments = ref([{user: {userImg: ''}}]);
  const comment = ref('');
  const router = useRouter();
  const route = useRoute();
  const imgUrl = getCurrentInstance()?.appContext.config.globalProperties.$imgUrl

  const workDetail = (work) => {
    router.push({path: '/workDetail', query: {id: work.workId}});
  };
  const getUserWorks = () => {
    let data = {};
    data.userId = route.query.id;
    selectUserWorks(data).then((res) => {
      worksInfo.value = res.data.data;
    })
  };

  onBeforeMount(() => {
    getUserWorks();
  });
</script>

<style scoped>
    .stage-flex-container {
        display: flex;
        width: 977px;
    }
    .swiper-painter-item {
        overflow: hidden;
        border-radius: 4px;
        display: flex;
        flex-wrap: wrap;
        margin-left: 100px;
    }
    .swiper-painter-cards {
        margin-top: 15px;
        height: 400px;
        margin-right: 10px;
        width: 300px;
    }
    .painter-item-name {
        max-width: 100px;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
        align-items: center;
        font-size: 14px;
        color: #333;
    }
    .introduction-motto {
        background-color: #ffffff;
        margin-top: 8px;
        font-size: 14px;
        word-break: break-all;
        overflow: hidden;
        text-overflow: ellipsis;
        text-align: justify;
        text-justify: inter-ideograph;
    }
    .image {
        width: 100%;
        height: 250px;
        display: block;
        margin: 0 auto
    }
    p {
        display: block;
        margin-block-start: 1em;
        margin-block-end: 1em;
        margin-inline-start: 0px;
        margin-inline-end: 0px;
    }
    .star-span {
        color: #adb3fb;
        float: right;
        background-color: #ffffff;
        margin-top: 20px;
    }
    .author-span {
        color: #777;
        font-size: 14px;
        max-width: 154px;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
        background-color: #ffffff;
    }
    .work-user-img {
        width: 55px;
        height: 55px;
        border-radius: 100%;
    }
    .work-div {
        background-color: #ffffff;
        margin-top: 20px;
        text-align: center;
    }
    .work-button {
        background-color: #ffffff;
        border: #fff;
        text-align: center;
    }
    .stage-flex-container {
        display: -webkit-box;
        display: -ms-flexbox;
        display: flex;
    }

    .stage-flex-container {
        display: flex;
    }
    a {
        text-decoration: none;
    }
    .stage-flex-container {
        display: flex;
    }



    .artwork-modal__operator i {
        color: #d8d8d8;
        font-size: 32px;
        margin-bottom: 5px;
    }
    .video_fo{
        position: relative;
        width: 283px;
        height: 200px;
        left: -20px;
    }
</style>
